<template>
  <div :class='wrpCls'>
    <a @click='gokhu(1)' style='color:#f5cb81;font-weight: bold;margin-right: 40px;font-size: 20px'>今日待跟进客户：{{ today_count }}</a>
    <a @click='gokhu(2)' style='color:#ee8585;font-weight: bold;margin-right: 20px;font-size: 20px'>逾期未跟进客户：{{ end_count }}</a>
    <!--    <a @click='showLogModel'>待跟进记录</a>-->
    <log-model ref='LogModel' />
    <avatar-dropdown :menu='showMenu' :current-user='currentUser' :class='prefixCls' />
    <!-- <select-lang :class="prefixCls" /> -->
  </div>
</template>

<script>
import AvatarDropdown from './AvatarDropdown'
import LogModel from '@/views/presales/list/LogModel/Index.vue'
import * as logApi from '@/api/presales_customer/log'
// import SelectLang from '@/components/SelectLang'

export default {
  name: 'RightContent',
  components: {
    LogModel,
    AvatarDropdown
    // SelectLang
  },
  props: {
    prefixCls: {
      type: String,
      default: 'ant-pro-global-header-index-action'
    },
    isMobile: {
      type: Boolean,
      default: () => false
    },
    topMenu: {
      type: Boolean,
      required: true
    },
    theme: {
      type: String,
      required: true
    }
  },
  data() {
    const currentUser = this.$store.getters.userInfo
    return {
      showMenu: true,
      currentUser,


      today_count: 0,
      end_count: 0
    }
  },
  computed: {
    wrpCls() {
      return {
        'ant-pro-global-header-index-right': true,
        [`ant-pro-global-header-index-${(this.isMobile || !this.topMenu) ? 'light' : this.theme}`]: true
      }
    }
  },
  methods: {
    gokhu(log_status) {
      this.$router.push({ path: '/presales/list', query: { log_status, newtime: Number(new Date) } })
    },
    showLogModel() {
      this.$refs.LogModel.queryParam.status = 0
      this.$refs.LogModel.open()
    },
    async getLogNumber() {
      const that = this
      const { data: { end_count, today_count } } = await logApi.getExpireLog()
      this.today_count = today_count
      this.end_count = end_count
      if (today_count || end_count) {
        this.$confirm({
          title: '客户跟进提示',
          content: '今日您有' + today_count + '条待跟进客户，已逾期未处理客户' + end_count + '条',
          okText: '前往查看',
          onOk() {
            if (today_count > end_count) {
              that.gokhu(1)
            } else {
              that.gokhu(2)
            }
            // that.$refs.LogModel.queryParam.status = 0
            // that.$refs.LogModel.open()
          },
          onCancel() {
            console.log('Cancel')
          }
        })
      }

      setInterval(async ()=>{
        const { data: { end_count, today_count } } = await logApi.getExpireLog()
        this.today_count = today_count
        this.end_count = end_count
      },3000)
    }

  },
  mounted() {
    this.getLogNumber()
  }
}
</script>
